package com.baizhi.controller;

import com.baizhi.dto.PageDTO;
import com.baizhi.entity.User;
import com.baizhi.service.UserService;
import com.baizhi.vo.CommonQueryPageVO;
import com.baizhi.vo.CommonVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;

@CrossOrigin
@RestController
@RequestMapping("user")
public class UserController {

    private static final Logger log = LoggerFactory.getLogger(UserController.class);
    @Resource
    UserService userService;

    @RequestMapping("queryAllPage")
    public CommonQueryPageVO queryAllPage(@RequestBody PageDTO pageDTO){

        log.info("当前页：{}",pageDTO.getPage());
        log.info("每页展示条数：{}",pageDTO.getPageSize());

        CommonQueryPageVO commonQueryPageVO = userService.queryAllPages(pageDTO.getPage(), pageDTO.getPageSize());

        return commonQueryPageVO;
    }
    /*@RequestMapping("update")
    public HashMap<String,Object>update(@RequestBody User user){

        log.info("修改用户数据：{}",user);

        return userService.update(user);
    }*/
    @RequestMapping("update")
    public CommonVO update(@RequestBody User user){

        log.info("修改用户数据：{}",user);

        return userService.updates(user);
    }
}
